//求和相关的配置
import {reqStudyList,addStudyListAxios,reqGitList,reqVueList,reqJsList} from '@/api'
export default {
	namespaced:true,
	state:{
		studyList:[
			{
			  "id": 1,
			  "name": "git",
			  "child": [
				{
				  "id": 1,
				  "title": "git常用指令",
				  "msg": "git init"
				},
				{
				  "id": 2,
				  "title": "远程推送",
				  "msg": "git add . ==> git commit -m '第一次提交' ==> git push origin master"
				}
			  ]
			},
			{
			  "id": 2,
			  "name": "vue",
			  "child": [
				{
				  "id": 1,
				  "title": "vue常用指令",
				  "msg": "git init"
				},
				{
				  "id": 2,
				  "title": "远程推送",
				  "msg": "git add . ==> git commit -m '第一次提交' ==> git push origin master"
				}
			  ]
			},
			{
			  "id": 3,
			  "name": "js",
			  "child": [
				{
				  "id": 1,
				  "title": "js常用指令",
				  "msg": "git init"
				},
				{
				  "id": 2,
				  "title": "远程推送",
				  "msg": "git add . ==> git commit -m '第一次提交' ==> git push origin master"
				}
			  ]
			}
		  ],
		newList:{
			name:'',
			title:'',
			msg:''
		}
	},
	actions:{
		async studyList({commit}){
			let result =await reqStudyList();
			commit("STUDYLIST",result)
		},
		addStudyList(context,value){
			let list = context.state.newList
			if(list.name&&list.title&&list.msg != ''){
				context.commit('ADDSTUDYLIST',list)
			}else{
				alert('不能输入为空！')
			}
		}
	},
	mutations:{
		STUDYLIST(state,studyList){
			state.studyList = studyList;
		},
		SETNEWLIST:(state,value)=>{
			state.newList= value;
		},
		ADDSTUDYLIST(state,value){
			addStudyListAxios(value),
			state.newList = {
				name:'',
				title:'',
				msg:''
			},
			location.reload()
		}
	},

	getters:{
		newList:state => state.newList
	},
}